package com.sangcomz.fishbun.util;

import ohos.agp.window.service.Window;
import ohos.agp.window.service.WindowManager;
import ohos.app.Context;
import ohos.global.configuration.Configuration;
import ohos.global.resource.NotExistException;
import ohos.global.resource.WrongTypeException;

import java.io.IOException;

/**
 * Created by sangc on 2015-11-20.
 */
public class UiUtil {

    public static void setStatusBarColor(Window window, int colorStatusBar) {
        if (colorStatusBar == Integer.MAX_VALUE) {
            return;
        }
        window.clearFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutConfig.MARK_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(colorStatusBar);
    }

    public static boolean isLandscape(Context context) {
        return context.getResourceManager().getConfiguration().direction == Configuration.DIRECTION_HORIZONTAL;
    }

//    inline fun <T : Context> T.isLandscape(block: () -> Unit) = if (isLandscape()) block() else Unit
//

    public static int getDimension(Context context, int id) throws NotExistException, WrongTypeException, IOException {
        return context.getResourceManager().getElement(id).getInteger();
    }

//    fun Resources.getDrawableFromBitmap(bitmap: Bitmap?) = bitmap?.let {
//        BitmapDrawable(this, it)
//    }

}
